home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 6 / Eagles_Nest_Mac_Collection_Disc_6.TOAST / Other Macintosh Text / HowToCrackAt / How_to_Crack
Text File  |  1990-10-02  |  23KB  |  427 lines

  1. ====== Mac Cracking- A series on deprotection methods on the Macintosh =======
  2. ====== Written by The Atom / Spring 1986
  3.  
  4.  
  5. Here it is.. First in the series of the Infamous Atom's mac crack series..
  6.  
  7. Some of you may have macs, others just wonder how you crack on the mac..
  8. In this series I'll attempt to show you the basics of cracking on a mac
  9. and hopefully give you an idea of the difficultly and difference between
  10. apple and mac cracking.
  11.  
  12. 1) Things that make mac cracking easier than apple:
  13.  
  14.   A) All code segments must be stored on the disk in normal format. No
  15.      abnormal headers or anything that cannot be read with the normal
  16.      ROM read routine.(data can be stored otherwise though)
  17.   B) Protection on the mac has used fairly simple techniques since the
  18.      programmers don't know all the tricks that they do on the II
  19.   C) All disk I/O has to pass through the IWM chip and thus you can't have
  20.      half and spiral tracking. 
  21.   
  22. 2) Things that make mac cracking harder than apple:
  23.  
  24.   A) No debugger(or monitor) in ROM.. Macsbug is a software debugger only and
  25.      therefore can be destroyed by some nasty programs(EA does it on all
  26.      of theirs)
  27.   B) Programs have much more memory to play with. Instead of 0-$C000, you have
  28.      $0-$400000 (  of course most of the top is ROM.)
  29.   C) Virtually no documentation on non-standard read routines. Basically have
  30.      to figure it out yourself.
  31.   
  32. The first thing you need to do before attempt a crack on the mac is learn
  33. 68000 assembly(duuh..).. WELL!! don't just look at it and assume you know
  34. it!! You must really understand the addressing modes and especially how
  35. the stack is handled. EVERYTHING on the mac uses the stack. The code you
  36. are following is constantly calculating addresses and placing them on the
  37. stack to RTS to.  Also, pick up a copy of Inside Mac.. So you can get a 
  38. basic Idea of the rom traps(there are over 300)
  39.  
  40. If you want to look for books, I suggest 68000 assembly by Leventhal. 
  41. And the Inside Mac phonebook or vol.1-3 from Apple
  42.  
  43. Next time I'll start showing you some traps, and a little 68000, then we'll
  44. jump right in to the debugger and cracking a ware- Wizardry!
  45.  
  46. ---------------------------------------------------------------------------
  47.  
  48. Welcome to part 2 of The Atom's guide to Mac cracking-
  49.  
  50. Today's Topic- 68000 assembly and Mac Traps
  51.  
  52. By now, I assume you have looked at the 68000 assembly language 
  53. somewhat and can at least understand small sections of code.
  54. Just to clarify things, and teach you some machine-dependent ideas
  55. (for the mac that is), I'll devote this part of the cracking series
  56. to the 68000 and traps/interrupts.
  57.  
  58. First of all, the 68000 is a two instruction machine, unlike the
  59. 6502. This means that most commands have 2 arguments rather than
  60. one(as the 6502 has).. IE> MOVE D0,#$1000 instead of STA #$1000.
  61. This makes life much easier, especially with the use of multiple registers.
  62. (68000 has 17, compared to the 4 on the 6502).
  63. These registers are labelled D0-7, A0-7, and the processor status reg.
  64. The registers starting with D are data registers which are 32 bits long.
  65. You can store any kind of 32 bit number in them. The address registers,
  66. (denoted by A), are also 32 bits long but can only refer to even numbered
  67. addresses and are not valid for all modes.(Don't worry if it doesn't make
  68. much sense, you'll get the hang of it)
  69.  
  70. Sooo.. Now we know about registers. How about operands? Unlike the 6502,
  71. which has a different command for each register, the 68000 has a standard
  72. set of commands which can work with all the regs. Instead of:
  73. STA #$1000, STY #$1000, you would have MOVE D0,#$1000, MOVE D1,#$1000,
  74. etc. The move (MOVE) command is the basic operand to move  data from
  75. one place to another. Be it from reg to reg (mov d0,d1) or memory to memory
  76. (mov #$1000,#$2000), or whatever. 
  77.  
  78. Most of the other commands are similar to 6502, and work pretty much the
  79. same(JSR,RTS,CMP,BEQ,BNE,etc.). There is one other addition to the syntax
  80. you should know- the .b, .w, and .l suffixes.  These refer to byte, word, and
  81. long word commands. By adding any of these to the end of an operand, you limit 
  82. the command to only that size of data. For instance, a MOVE.B D0,D1
  83. would move the first 8 bits of D0 into the first 8 bits of D1. The word
  84. command uses 16 bits, and long word uses 32. These can be added to most
  85. commands that manipulate data, like CMP,CLR,MOV,ROL, etc. If you ignore the 
  86. syntax, it defaults to .w.
  87.  
  88. Now we get to Addressing modes: On the 6502, you had different syntax for
  89. addressing, and its about the same on the 68000. An indirect 
  90. jump (JMP ($1000)) would become JMP ($1000)... really hard huh? or you can
  91. use inderict in mov commands also- MOVE (A0),D1. This would move the 
  92. contents of whatever address was in A0 into D1.(IF $1000 was in A0, then 
  93. the contents of $1000 would go to D1). One note, the indirect mode can only 
  94. be used with the address registers, not the data registers.
  95.  
  96. Finally, there are the auto-increment and auto-decrement indirect modes.
  97. If you did a MOVE (A0)+,D1, it would the contents of $1000 into d1, and then
  98. automatically increment A0 so it now points to $1002.(It increments by 2 
  99. since it moved a word(16 bits) and each address points to a byte( in affect,
  100. its now pointing to the next WORD)).  Auto-decrement works basically the
  101. same way, a MOVE -(A0),D1, would decrement the address in A0 by 2, then
  102. move the contents of $FFE into D1. The placement of the - or + is the way
  103. its set up, so you can't do a MOV +(A0),D1 or MOV (A0)-,D1.
  104.  
  105. And a couple more sytnax things- there are no stack commands(PHA,etc.),they
  106. use the auto-inc and auto-dec modes to implement a stack with the A7 
  107. register.  Its kind of complicated exactly how it works, so I won't go into it
  108. here, but just assume that MOVE D0,-(A7) pushes D0 onto the stack and 
  109. MOVE (A7)+,D0 pops the value off the stack into D0. (the A7 is sometimes
  110. replaced by SP as in MOVE D0,-(SP)).
  111.  
  112. So now we know everything there is to know about 68000 assembly, right?
  113. Wrong... But we know enough to crack something!
  114.  
  115.  
  116. But before I start talking about the debugger, I'll mention something about
  117. the traps on the 68000. Since all ROM routines are called through these,
  118. it pays to know what they are.
  119.  
  120. First of all, when the 68000 finds an opcode it doesnt know (some code that
  121. doesnt translate into an executable instruction), it will look in a trap 
  122. table to see if there is a replacement code for it. This way, you can 
  123. implement your own 68000 commands by putting the address of your routine
  124. into the trap table and simply issuing the command. On the mac, the trap
  125. tables are in low memory and point to ROM routines.  Since the routines are
  126. always in the same place with the same ROMS, the debugger keeps a table of
  127. these traps and will actually name them for you in the code.. So while listing
  128. a section of memory you may see something like this:
  129.  
  130.         _InitGraf
  131.         _InitFonts
  132.         _InitWindows
  133.         Mov #14,D0
  134.         Mov D0,-(SP)
  135.         _Read
  136.  
  137. What it is doing is calling three rom routines to initialize different
  138. sections of the window management, executing a couple of 68000 instructions 
  139. and then calling the Read ROM routine to read from the disk.  Fairly simple,
  140. right? It does make cracking quite a bit easier, as long as you know what 
  141. most of the traps do. So be sure and have a copy of Inside Mac at hand when
  142. you  start to debug/crack something.(and lots of paper)
  143.  
  144. Well, next time, we'll look at the debugger and start trying to crack
  145. a few warez...
  146.  
  147. --------------------------------------------------------------------
  148.  
  149. Here we are again, with the 3rd installment of "Mac Cracking- man or myth?"
  150. (or something like that).
  151.  
  152. The topic of discussion in this section will be the DEBUGGER.. Otherwise
  153. known as MACSBUG.  If you end up doing much cracking at all, you'll begin
  154. to love(and hate) some of macsbugs commands, and you should get fairly 
  155. familiar with reading other people's  68000 code.(or compiler code).
  156.  
  157. First, a couple notes about macsbug: To run it, you must have the macsbug
  158. file on the disk you are booting up, and it must be named MACSBUG.. exactly,
  159. (well, case doesnt matter, but otherwise, exactly like that ^^^).
  160. If you are using the HFS system, it must be in the system folder along with
  161. the system and finder files.  Also, don't forget to install the little 
  162. programmers switch in the side of your mac.. If you don't have it in, you
  163. can't even start up macsbug!
  164.  
  165. Ok, well, I'll start by talking about how macsbug is loaded in, set up,
  166. and then list some commands and show you some examples.
  167.  
  168. Booting up-  When the mac boots up, it reads a bunch of system related stuff
  169. from the boot disks, initializes the font,quickdraw, resource and other
  170. managers, and then throws up a Dialog saying "Welcome to Macintosh". It
  171. then looks for a file name MACSBUG on the disk, and if it finds it, it
  172. allocates some extra memory for it and then loads it in and sets it all up.
  173. Macsbug takes up about 40k, so for large programs, running on a 128k, you
  174. may not be able to load it.(get a 512k!)
  175.   
  176. Basically what macsbug does when it sets up is change a few pointers in
  177. low ram that used to point to error routines to point to it. Like the
  178. error when you hit the interrupt button on the side of the computer(plus
  179. a few more). So now, when you hit the interrupt button, instead of getting
  180. a bomb dialog, a new window will pop up, covering most of the screen, with
  181. a dump of all the registers(d0-d7 and a0-a7 as well as the PC and some
  182. other info).  You are now in Macsbug! You have stolen control of the 68000
  183. from the executing program and can now debug(or crack) to your hearts 
  184. content.  But first, you need to know the macsbug commands!
  185.  
  186. Commands
  187. --------
  188.  
  189. Macsbug has a lot of commands. At least 40. It basically works the same as
  190. the monitor on a II, but with different syntax, and a bunch of nice tracing
  191. functions. They are set up in a general format of a one or two word command,
  192. followed by a few numeric parameters. 
  193.  
  194.  What follows is a partial list of the basic commands we will be
  195. using to crack Wizardry, and some explanation for each. To get a list of all
  196. the commands, look in your Inside Mac manual under the section called 
  197. "INSIDE MACSBUG"(only in newer versions.)
  198.  
  199. Oh yea, forgot to mention, I'm using Macsbug V5.1. These commands work with
  200. all versions 5.0 and higher.(you can check your version of macsbug by typing
  201. DV <cr> at the prompt)
  202.  
  203. (aaaa = address, nnnn = number)
  204.  
  205. Memory Commands:
  206.  
  207.   DM aaaa nnnn          Display memory- gives you hex dump of the bytes 
  208.                         starting at aaaa and going up to address aaaa+nnnn
  209.   ex. DM 0f00 10        Would dump out hex from $f00 to $f10
  210.                         If you leave out the nnnn, it lists the next 16 bytes.
  211.                         If you leave out aaaa, it starts at the current address.
  212.  
  213.   SM aaaa nn,nn1,nn2..  Set memory- changes value in address aaaa to nn, then
  214.                         address aaaa+1 to nn1, etc.
  215.  
  216.   TD                    Total Display- dumps out all the registers, PC and
  217.                         disassembles the current line
  218.                 
  219. Break Commands:
  220.  
  221.   BR aaaa               Sets a break point at address aaaa. When the program
  222.                         executes the line at aaaa, it will be interrupted and
  223.                         the macsbug window will pop up.
  224.  
  225.   G aaaa                Just like the apple, starts execution at aaaa. If you
  226.                         leave off aaaa, it starts where the PC last was.
  227.  
  228.   GT aaaa               Very nice command, starts executing at the PC, and then
  229.                         stops and returns to macsbug when it gets to address
  230.                         aaaa. (easier than setting breakpoints)
  231.  
  232.   T                     Trace, executes one instruction, then dumps out the
  233.                         registers and disassembles the next line
  234.  
  235.   MR                    Magic return. If you are tracing along, and suddenly
  236.                         encounter a JSR, you can type MR and it will execute
  237.                         the subroutine and then return you to trace mode 
  238.                         right after it gets a RTS.
  239.  
  240. A Trap commands:
  241.  
  242. (these are probably the most important, be sure you understand them)
  243.  
  244.   AB TRAPNAME           Causes the computer to halt to return to macsbug when
  245.                         it sees a TRAP command that is referred to by
  246.                         TRAPNAME
  247. ex. AB READ             This would stop the next time the program does a
  248.                         READ call.
  249.  
  250.   AT TRAPNAME           Traces and displays the address of each call to the
  251.                         trap TRAPNAME. Doesnt halt though.
  252. ex. AT EJECT            Would show the address of each line that the program
  253.                         executed that called the EJECT trap, and then continue
  254.                         executing the program
  255.  
  256.   AX                    Clear all trap commands.(so it won't stop everytime it
  257.                         does a READ anymore)
  258.  
  259. Disassembler commands:
  260.  
  261.   IL aaaa nnnn          List out disassembled code starting at address aaaa
  262.                         and going until address aaaa+nnnn.. Just like the
  263.                         L command on the II.
  264.                         If you just enter IL <CR> it will list out the
  265.                         next 10 or so instructions.
  266.  
  267. So those are all the commands you need to know! there are a bunch more, but
  268. they aren't as powerful or easy to understand as these, so you can learn them
  269. on your own.
  270.  
  271.  
  272. Just to give you and example of using the debugger, I'll show the steps you
  273. might use to find the starting address of a program:
  274.  
  275. 1) put macsbug on the disk with the program you are trying to find the 
  276.    starting address for(Well call it PROGRAM)
  277. 2) Boot up the disk, and go to the desktop.
  278. 3) Press the interrupt button- you should see a big window pop up with a 
  279.    dump of the registers in it.
  280. 4) Type AB INITGRAF
  281.    This tells macsbug to stop the next time it encounters an INITGRAF call.
  282.    (initgraf is usually one of the first instructions applications run, so
  283.     it will close to the starting address)
  284. 5) Hit G to start the finder running again.
  285. 6) Double click on PROGRAM and hope for the best!
  286. 7) If all goes ok, macsbug should pop up in a little while, displaying the
  287.    address of the instruction that call INITGRAF.  
  288. 8) Type IL aaaa, where aaaa is the address that macsbug said the initgraf
  289.    instruction was at. 
  290. 9) Thats it! the beginning of the code for our application! from there,
  291.    we could trace on using the T command and watch the execution of the
  292.    program. Or hit G to give the program back full control of the 68000.
  293.  
  294. Don't forget to do an AX command when you are done, otherwise you will be
  295. jumping into macsbug everytime you run an application that calls INITGRAF.
  296.  
  297. Finally, I'd like to say something about macsbug alternatives:
  298. I know of one great debugger called MCBUG. it works a lot like macsbug,
  299. but has a few extra features that help a lot, like a built in mini-assembler,
  300. some nice launch funtions, and a few other helpful commands. Its a shareware/
  301. public domain program, so if you look around you should be able to find
  302. a copy of it on compuserve or from a user group. It comes with docs, and 
  303. installs just like macsbug; simply rename it and boot!
  304.  
  305. ---------------------------------------------------------------
  306.  
  307. Welcome to Part 4 of Mac Cracking- your guide to fame.
  308.  
  309. In this, the fourth, and hopefully final part, we will look at Wizardry and
  310. actually remove its protection. Of course, as we all know, this is only for
  311. backup purposes, right?
  312.  
  313. So first we need to set up a copy of the disk to work on. Wizardry is a
  314. unusual protection, in that you can copy all the files off the disk, but
  315. it asks you to put the master disk back in upon boot, and then reads some
  316. bad blocks off of the master disk. The nice thing about this method is that
  317. it does not crash the machine if it can't find the master, it simply 
  318. continues with a semi-demo game of Wiz. This saves a lot of time when you
  319. are constantly backtracking and reloading the files to find the protection.
  320.  
  321. Here we go!
  322.  
  323. First, sector copy (or finder copy) the files from the wizardry disk onto
  324. a blank. Then trash the Imagewriter file (we need more space for macsbug).
  325. Copy macsbug onto the Wizardry disk, and then select the Wizardry file,
  326. and install a minifinder with only Wizardry in the selection. This way, when
  327. the disk boots up, we can set up some breakpoints while the minifinder is
  328. running, and then execute Wizardry. If we let it boot straight into Wizardry,
  329. we would have to guess when to hit the interrupt switch and hope that we
  330. didn't miss something.
  331.  
  332. Now we have a disk to crack. Boot up the disk, and when you see the minifinder,
  333. hit the interrupt switch. Macsbug should come up. Type AB INITGRAF <cr>.
  334. This will find the starting address of the program by halting when it starts
  335. initializing the managers. Now type G . You are back in the minifinder, so
  336. double click on the wizardry file and wait for macsbug to regain control.
  337.  
  338. At this point, macsbug should appear saying it halted on a Initgraf call
  339. at location F200 (this address will be different depending on your memory
  340. size. F200 is on a 512 or plus). You can now type IL F200 to start listing
  341. the code. As we look at the code (hit return to see another 20 lines after
  342. you are done with a section) we see that the program contains no branching
  343. until address F222. The protection check is going to involve reading a sector
  344. from the disk and then branching on a result. So all we have to look for
  345. is a branch after some disk access.
  346.  
  347. Type GT F222. Wizardry loads in some resources and sets up its menus and 
  348. windows. If you booted up your copy of wizardry normally, this is right before
  349. it puts up a dialog and asks for the key disk. Now we have to narrow down
  350. the search to a specific JSR. If you try GT F322, you see that it goes through
  351. the check and comes back with a message that you did not insert the master
  352. disk. This means that the JSR to the protection routine is somewhere between
  353. F222 and F322. So now we look some more!
  354.  
  355. (If you did try the GT F322, you can type EA to exit to the application,
  356. re-running Wizardry. It will abort again at the Initgraf, and then you
  357. can type GT F222 to get back to where you belong)
  358.  
  359. By continuing this process(trying locations closer and closer to F222 in
  360. the GT command) you will eventually find that the JSR to the protection
  361. is at F31E. The program does not throw up a dialog saying you inserted the
  362. wrong disk before this JSR, but does draw a dialog at F322, the next
  363. statement. So we have tracked it down to a single JSR.. Now we can have fun.
  364.  
  365. If we trace, using the T command at this subroutine, we find that it
  366. immediately executes a Loadseg trap. And then for some mysterious reason,
  367. macsbug never regains control. This is the tricky part- After the JSR to
  368. EFB7A (the loadseg), the program loads the protection routine from disk
  369. AND loads code into EFB7A. Since the T command replaces the code at the
  370. next instruction with a break command in order to regain control after 
  371. one step, this code is loaded on top of the break command, replacing it. 
  372. This is why your macsbug never comes back. There is not a break point to
  373. interrupt the program any more! 
  374.  
  375. What we can do though, is interrupt with the interrupt switch after it
  376. brings up a dialog saying we inserted the wrong disk, and disassemble the
  377. code that was loaded into EFB7A. When we look there, we see it did a
  378. JMP to 13828. The code at 13828 was also loaded in with this loadseg trap,
  379. so we didnt see it before. This is the main protection routine.
  380.  
  381. But now we have a problem- how do we stop the execution of the program at
  382. 13828 so we can trace the protection and find the correct branch? We can't
  383. set a breakpoint at 13828 with GT, since it would get replaced with the
  384. code during the Loadseg. And we can't stop it after the Loadseg since it
  385. replaces itself and any breakpoints we set after it! What do we do??
  386. Alas, macsbug comes through with yet another amazing command. ST .
  387. This works like the GT, but does not set a breakpoint to stop the program.
  388. (I'm not sure what it does to do this, but it uses the 68000 step flag)
  389.  
  390. So we get back to F31E (using the EA command as before, then the GT).
  391. And type ST 13828. The reason we don't issue a ST right after F200 is
  392. that the S commands slow execution of the program noticeably. You will have
  393. to wait a couple of minutes for the ST 13828 to return to macsbug. (The
  394. drive will make some strange noises, but don't worry.. just be patient)
  395.  
  396. After this hard work, we are now in trace mode at 13828. Hurrah! Almost
  397. there. Be repeating the method we used to find the first JSR, and by
  398. reading the code, you find that the last branch that seperates a key disk
  399. dialog from the bad disk dialog is at 139D0. The BEQ +90 is executed if 
  400. the protection check comes out bad. If you search the code, you see that
  401. the good code continues 3 instructions from the address the BEQ branches
  402. to. So now we simply replace the BEQ with BRA +98, and no matter what the
  403. protection check returns, everything continues fine.
  404.  
  405. Now to test a be sure our patch works. Boot the disk from scratch and get
  406. to the trace mode at 13828 using the commands we used before. Now type
  407. SM 139D0 60 00 00 98 . This is the code for a BRA +98, which we are replacing
  408. at 139D0. Hit G, and there it is! Your copy should continue to load, and
  409. no matter what disk you put in for the master, it will thank you for inserting
  410. your "master" and continue along its merry way. 
  411.  
  412. But we don't want to have to use macsbug to does this EVERY time we boot
  413. up, so we'll change the program on the disk. First, dump the memory from
  414. the instructions before and after the BEQ +90 and write them down. Then
  415. run Fedit (its a sector editor program) and open the file Wizardry on your
  416. cracking disk. Do a hex search for the values-
  417. 0A 00 00 01 67 00 00 90 30 2E FF F2
  418. (These are the bytes surrounding the instruction that you wrote down earlier.
  419.  By searching for the whole string, we are sure we have the correct 
  420.  Beq +92 in the program, in case there is more than one).
  421. Go in to hex edit mode and replace the 67 00 00 90 with 60 00 00 98. And
  422. write the sector back out. 
  423.  
  424. Congratulations, you have successfully cracked Wizardry. You can copy the 
  425. Wizardry file you patched onto your master disk, or make the patch to a
  426. sector copy of the original to get the disk back looking like it normally
  427. did.(Auto boot into wizardry, no macsbug or minifi